/*  Copyright (c) 2010 Xiaoyun Zhu
 * 
 *  Permission is hereby granted, free of charge, to any person obtaining a copy  
 *  of this software and associated documentation files (the "Software"), to deal  
 *  in the Software without restriction, including without limitation the rights  
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell  
 *  copies of the Software, and to permit persons to whom the Software is  
 *  furnished to do so, subject to the following conditions:
 *  
 *  The above copyright notice and this permission notice shall be included in  
 *  all copies or substantial portions of the Software.
 *  
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE  
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN  
 *  THE SOFTWARE.  
 */
package cn.kk.exia;

public class OptionsPanel extends javax.swing.JPanel {
  private static final long serialVersionUID = 1019505904452333279L;

  public boolean[] getTypes() {
    return new boolean[] { this.chkDouhinshi.isSelected(), this.chkManga.isSelected(), this.chkArtist.isSelected(), this.chkGame.isSelected(),
        this.chkWestern.isSelected(), this.chkNon.isSelected(), this.chkImageSet.isSelected(), this.chkCosplay.isSelected(), this.chkAsian.isSelected(),
        this.chkMisc.isSelected() };
  }

  public boolean[] getSearchFields() {
    return new boolean[] { this.chkSearchName.isSelected(), this.chkSearchTags.isSelected(), this.chkSearchDescription.isSelected() };
  }

  public int getMinimumStars() {
    return this.cbStars.getSelectedIndex() + 1;
  }

  /**
   * Creates new form OptionsPanel
   * 
   * @param minimumStars
   * @param optionsSearchFields
   * @param optionsTypes
   */
  public OptionsPanel(final boolean[] optionsTypes, final boolean[] optionsSearchFields, final int minimumStars) {
    this.initComponents();
    int minStars = minimumStars;
    if ((minStars < 1) || (minStars > 5)) {
      minStars = 1;
    }
    this.cbStars.setSelectedIndex(minStars - 1);
    for (int i = 0; i < optionsSearchFields.length; i++) {
      final boolean selected = optionsSearchFields[i];
      switch (i) {
        case 0:
          this.chkSearchName.setSelected(selected);
          break;
        case 1:
          this.chkSearchTags.setSelected(selected);
          break;
        case 2:
          this.chkSearchDescription.setSelected(selected);
          break;
        default:
          break;
      }
    }
    for (int i = 0; i < optionsTypes.length; i++) {
      final boolean selected = optionsTypes[i];
      switch (i) {
        case 0:
          this.chkDouhinshi.setSelected(selected);
          break;
        case 1:
          this.chkManga.setSelected(selected);
          break;
        case 2:
          this.chkArtist.setSelected(selected);
          break;
        case 3:
          this.chkGame.setSelected(selected);
          break;
        case 4:
          this.chkWestern.setSelected(selected);
          break;
        case 5:
          this.chkNon.setSelected(selected);
          break;
        case 6:
          this.chkImageSet.setSelected(selected);
          break;
        case 7:
          this.chkCosplay.setSelected(selected);
          break;
        case 8:
          this.chkAsian.setSelected(selected);
          break;
        case 9:
          this.chkMisc.setSelected(selected);
          break;
        default:
          break;
      }
    }
  }

  /**
   * This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always
   * regenerated by the Form Editor.
   */
  // <editor-fold defaultstate="collapsed" desc="Generated Code">
  private void initComponents() {

    this.chkDouhinshi = new javax.swing.JCheckBox();
    this.chkManga = new javax.swing.JCheckBox();
    this.chkArtist = new javax.swing.JCheckBox();
    this.chkGame = new javax.swing.JCheckBox();
    this.chkWestern = new javax.swing.JCheckBox();
    this.chkNon = new javax.swing.JCheckBox();
    this.chkImageSet = new javax.swing.JCheckBox();
    this.chkCosplay = new javax.swing.JCheckBox();
    this.chkAsian = new javax.swing.JCheckBox();
    this.chkMisc = new javax.swing.JCheckBox();
    this.cbStars = new javax.swing.JComboBox();
    this.chkSearchName = new javax.swing.JCheckBox();
    this.chkSearchTags = new javax.swing.JCheckBox();
    this.chkSearchDescription = new javax.swing.JCheckBox();
    this.jLabel1 = new javax.swing.JLabel();

    this.chkDouhinshi.setSelected(true);
    this.chkDouhinshi.setText("同人志");

    this.chkManga.setSelected(true);
    this.chkManga.setText("漫画");

    this.chkArtist.setText("艺术创作");

    this.chkGame.setText("游戏");

    this.chkWestern.setSelected(true);
    this.chkWestern.setText("欧美");

    this.chkNon.setText("无色情");

    this.chkImageSet.setText("图片");

    this.chkCosplay.setText("角色扮演");

    this.chkAsian.setSelected(true);
    this.chkAsian.setText("亚洲");

    this.chkMisc.setText("其它");

    this.cbStars.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1星以上", "2星以上", "3星以上", "4星以上", "5星" }));
    this.cbStars.setSelectedIndex(4);

    this.chkSearchName.setSelected(true);
    this.chkSearchName.setText("漫画名");

    this.chkSearchTags.setSelected(true);
    this.chkSearchTags.setText("标签");

    this.chkSearchDescription.setSelected(true);
    this.chkSearchDescription.setText("描述");

    this.jLabel1.setText("范围：");

    final javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
        layout
            .createSequentialGroup()
            .addContainerGap()
            .addGroup(
                layout
                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(
                        layout
                            .createSequentialGroup()
                            .addComponent(this.cbStars, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                                javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(this.jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkSearchName)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkSearchTags)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkSearchDescription))
                    .addGroup(
                        layout.createSequentialGroup().addComponent(this.chkDouhinshi).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(this.chkManga).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkArtist)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkGame)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkWestern))
                    .addGroup(
                        layout.createSequentialGroup().addComponent(this.chkNon).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(this.chkImageSet).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkCosplay)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkAsian)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(this.chkMisc)))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
    layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGroup(
            layout
                .createSequentialGroup()
                .addContainerGap()
                .addGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.chkDouhinshi).addComponent(this.chkManga)
                        .addComponent(this.chkArtist).addComponent(this.chkGame).addComponent(this.chkWestern))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(
                    layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(this.chkNon).addComponent(this.chkImageSet)
                        .addComponent(this.chkCosplay).addComponent(this.chkAsian).addComponent(this.chkMisc))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(
                    layout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(this.cbStars, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
                            javax.swing.GroupLayout.PREFERRED_SIZE).addComponent(this.chkSearchName).addComponent(this.chkSearchTags)
                        .addComponent(this.chkSearchDescription).addComponent(this.jLabel1))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
  }// </editor-fold>
   // Variables declaration - do not modify

  private javax.swing.JComboBox cbStars;

  private javax.swing.JCheckBox chkArtist;

  private javax.swing.JCheckBox chkAsian;

  private javax.swing.JCheckBox chkCosplay;

  private javax.swing.JCheckBox chkDouhinshi;

  private javax.swing.JCheckBox chkGame;

  private javax.swing.JCheckBox chkImageSet;

  private javax.swing.JCheckBox chkManga;

  private javax.swing.JCheckBox chkMisc;

  private javax.swing.JCheckBox chkNon;

  private javax.swing.JCheckBox chkSearchDescription;

  private javax.swing.JCheckBox chkSearchName;

  private javax.swing.JCheckBox chkSearchTags;

  private javax.swing.JCheckBox chkWestern;

  private javax.swing.JLabel    jLabel1;
  // End of variables declaration
}
